package com.example.controller;

import com.example.common.Result;
import com.example.entity.Question;
import com.example.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    // 获取所有题库信息
    @GetMapping("/listQuestion")
    public Result listQuestion(@RequestParam String keyword) {
        List<Question> questions = questionService.selectAll(keyword);
        return Result.success(questions);
    }

    //添加
    @PostMapping("/addQuestion")
    public Result addQuestion(@RequestBody Question question) {
        questionService.addQuestion(question);
        return Result.success();
    }
    //编辑
    @PutMapping("/updateQuestion")
    public Result updateQuestion(@RequestBody Question question) {
        questionService.updateById(question);
        return Result.success();
    }
    //删除
    @DeleteMapping("/deleteQuestion/{id}")
    public Result deleteQuestion(@PathVariable Long id) {
        questionService.deleteById(id);
        return Result.success();
    }
}
